package com.wangjiyuan.giftshuo.ui.activity.classify.strategy_details.column_details.all_details;

import com.wangjiyuan.giftshuo.bean.classifybean.strategy.ColumnBean;

import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by QXL on 2016/11/21.
 */

public class ColumnDetailsPresenter implements ColumnDetContract.IColumnPresenter {
    private ColumnDetContract.IColumnModel iColumnModel;
    private ColumnDetContract.IColumnView iColumnView;

    private Subscription subscribe;

    public ColumnDetailsPresenter(ColumnDetContract.IColumnView view){
        iColumnModel=new ColumnDetailsModel();
        this.iColumnView=view;
    }
    @Override
    public void getColumDetailsObservable(int limit, int offset) {
        Observable<ColumnBean> columDetailsObservable = iColumnModel.getColumDetailsObservable(limit, offset);
        subscribe = columDetailsObservable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ColumnBean>() {
                    @Override
                    public void onStart() {
                        super.onStart();
                    }

                    @Override
                    public void onCompleted() {
                        subscribe.unsubscribe();
                    }

                    @Override
                    public void onError(Throwable e) {
                        subscribe.unsubscribe();
                    }

                    @Override
                    public void onNext(ColumnBean columnBean) {
                        iColumnView.loadData(columnBean);
                        int size = columnBean.getData().getColumns().size();
                    }
                });
    }
}
